import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileUtils {

    /**
     * 用字符流复制文本文件
     *
     * @param src 源文件路径
     * @param dest 目标文件路径
     */
    public static void copyTextFile(String src, String dest) {
        try (BufferedReader reader = new BufferedReader(new FileReader(src));
             BufferedWriter writer = new BufferedWriter(new FileWriter(dest))) {
            String line;
            while ((line = reader.readLine()) != null) {
                writer.write(line);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 用字节流读取文件内容，按行存入List<String>并返回
     *
     * @param filePath 文件路径
     * @return 包含文件各行内容的List
     */
    public static List<String> readLines(String filePath) {
        List<String> lines = new ArrayList<>();
        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
             BufferedReader reader = new BufferedReader(new InputStreamReader(bis))) {
            String line;
            while ((line = reader.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}